//店面管理-商品排期列表-配置文件
App.util.ns('Admin.Storefront.Schedule');
Admin.Storefront.Schedule.Conf = {
    columns: [
        {name: '名称', value: 'name'},
        {name: '店面', width: '120px', value: function(item){
            return item.storefront ? item.storefront.name : '-- --';
        }},
        {name: '柜体', width: '190px', value: function(item){
            return item.cabinet ? item.cabinet.name : '-- --';
        }},
        {name: '预期开始时间', width: '90px', value: function(item){
            return App.util.formator.date(item.start_time);
        }},
        {name: '预期结束时间', width: '90px', value: function(item){
            return App.util.formator.date(item.end_time);
        }},
        {name: '状态', width: '120px',value: function(item){
            switch (item.status+'') {
                case '0':
                    return '待更新柜体商品';
                case '1':
                    return '上线';
                case '2':
                    return '下线';
            }
        }},
        {name: '创建日期', width: '90px', value: function(item){
            return App.util.formator.date(item.created_at);
        }}
    ],
    form: [
        {type: 'hidden', name: 'id'},
        {type: 'input', name: 'name', title: '名称', required: true, maxLength: 40, rule: {
            type: 'str',
            range: [1, 40]
        }},
        {type: 'date', name: 'start_time', title: '开始时间', required: true},
        {type: 'date', name: 'end_time', title: '结束时间', required: true},
        {type: 'chosen', name: 'storefront_id', title: '店面',required: true,
            items: App.models.get('storefront-all'),
            item_key: 'id',
            item_name: 'name',
            value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            },
            onChange:function (self) {
                var cabinets = App.models.get('cabinets-all');
                var cabinets_index = [];
                for (var i=0;i<cabinets.data.length;i++) {
                    var cabinet = cabinets.data[i];
                    if(cabinet.storefront_id == self.value()){
                        cabinets_index.push([cabinet.id,cabinet.name]);
                    }
                }
                self.form.formItems['cabinet_id'].config.items = cabinets_index;
                self.form.formItems['cabinet_id'].flush();
            },
        },
        {type: 'chosen', name: 'cabinet_id', title: '柜体',required: true,
            items: App.models.get('cabinets-all'),
            // item_key: 'id',
            // item_name: 'name',
            // value_key: 'id',
            rule:{
                type: 'num',
                range: [1, 10]
            }
        },
        {type: 'selectLists', name: 'theme_id', title: '专题', required: true,
            data_id: 'id',
            data_name: function(item){
                return item.id+':'+item.name;
            },
            dataTable: {
                baseUrl: '/admin/goods/jmtheme',
                dataUrl: 'lists?status=1',
                data_id: 'id',
                data_name: 'name',
                table: {
                    id: 'id',
                    main: 0,
                    columns: [
                        {name: '专题名', value: 'name'}
                    ]
                },
                filter: [
                    {type: 'keywords'}
                ],
                height: '720px'
            }
        }
    ]
};